#include "GameHero.h"
#include "GameSettings.h"

bool GameHero::initAtPoint(CCPoint point, CCLayer *layer) {
	bool bRet = false;

	do {
		heroSprite = CCSprite::create("down.png");
		layer->addChild(heroSprite);
		heroSprite->setPosition(point);
		kact = kStay;
		speed = 8;
		bRet = true;
	} while (0);

	return bRet;

}

void GameHero::changeWithSpriteFile(const char *fileName) {

	CCSprite *sprite = CCSprite::create(fileName);
	heroSprite->setTexture(sprite->getTexture());
}

void GameHero::moveLeft() {
	this->changeWithSpriteFile("left.png");
	kact = kLeft;
	org = kl;

	CCPoint heroPos = heroSprite->getPosition();
	heroSprite->setPosition(ccp(heroPos.x-speed, heroPos.y));
}

void GameHero::moveDown() {
	this->changeWithSpriteFile("down.png");
	kact = kDown;
	org = kd;

	CCPoint heroPos = heroSprite->getPosition();
	heroSprite->setPosition(ccp(heroPos.x, heroPos.y-speed));

}

void GameHero::moveRight() {
	this->changeWithSpriteFile("right.png");
	kact = kRight;
	org = kr;
	
	CCPoint heroPos = heroSprite->getPosition();
	heroSprite->setPosition(ccp(heroPos.x+speed, heroPos.y));
}

void GameHero::moveUp() {

	this->changeWithSpriteFile("up.png");
	kact = kUp;
	org = ku;
	CCSprite *tile;
	
	CCPoint heroPos = heroSprite->getPosition();

	/*
	for (int i=0; i<tileArray->count; i++) {
	
		tile = tileArray->objectAtIndex(i);
		CCPoint tilePos = tile->getPosition();
		if (tile->getPosition().y - heroSprite->getPosition().y == TileHeight ) {
			if (tile->getPosition().x == heroSprite->getPosition().x) {
				return;
			}
			if (tilePos.x > heroPos.x && tilePos.x - heroPos.x < TileWidth)
		}

	}
	*/

	heroSprite->setPosition(ccp(heroPos.x, heroPos.y+speed));
}

void GameHero::onFire(CCSprite *bomb) {
	kact = kFire;
}

void GameHero::onStay() {
	kact = kStay;
}

